﻿Imports System.Net.Mail
Imports System.Data.OleDb

Public NotInheritable Class GeneralMethods

    Shared Sub SendMail(from As String, subject As String, body As String)
        Try

            Dim SmtpServer As New SmtpClient()
            Dim mail As New MailMessage()
            SmtpServer.Host = "smtp.gmail.com"
            SmtpServer.Port = 587
            SmtpServer.EnableSsl = True
            SmtpServer.UseDefaultCredentials = False
            SmtpServer.Credentials = New Net.NetworkCredential("keerthijmutt", "7448033171")
            mail = New MailMessage()
            mail.From = New MailAddress(from)
            mail.To.Add("keerthijmutt@gmail.com")
            mail.Subject = subject
            mail.Body = body
            Dim userState As String = "Email Sent"
            SmtpServer.SendAsync(mail, userState)
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    Shared Sub SendMail(subject As String, body As String)
        Try

            Dim SmtpServer As New SmtpClient()
            Dim mail As New MailMessage()
            SmtpServer.Host = "smtp.gmail.com"
            SmtpServer.Port = 587
            SmtpServer.EnableSsl = True
            SmtpServer.UseDefaultCredentials = False
            SmtpServer.Credentials = New Net.NetworkCredential("keerthijmutt", "7448033171")
            mail = New MailMessage()
            Using oledbReader As OleDbDataReader = DataAccessLayer.ExecuteDataReader("SELECT aspnet_Membership.Email FROM (UserProfile INNER JOIN aspnet_Users ON UserProfile.UserName = aspnet_Users.UserName) INNER JOIN aspnet_Membership ON aspnet_Users.UserId = aspnet_Membership.UserId WHERE (((UserProfile.EmailSubscription)='True'));")
                While oledbReader.Read
                    If Not IsDBNull(oledbReader.Item(0)) Then
                        mail.To.Add(New MailAddress(oledbReader.Item(0).ToString()))
                    End If

                End While
                oledbReader.Close()
            End Using
            mail.Subject = subject
            mail.IsBodyHtml = True

            mail.Body = body
            Dim userState As String = "Email Sent"
            SmtpServer.SendAsync(mail, userState)
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub


End Class
